package com.ecfront.test;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import com.ecfront.dao.*;
import com.ecfront.pojo.*;
import com.ecfront.test.dao.SpringUtilTest;

public class InitData {
	private static final AdminDAO adminDao = (AdminDAO)SpringUtilTest.getBean("AdminDAO");
	private static final BannerDAO bannerDao = (BannerDAO)SpringUtilTest.getBean("BannerDAO");
	private static final GoodsBrandDAO goodsBrandDao = (GoodsBrandDAO)SpringUtilTest.getBean("GoodsBrandDAO");
	private static final GoodsComplainDAO goodsComplainDao = (GoodsComplainDAO)SpringUtilTest.getBean("GoodsComplainDAO");
	private static final GoodsDAO goodsDao = (GoodsDAO)SpringUtilTest.getBean("GoodsDAO");
	private static final GoodsImplDAO goodsImplDao = (GoodsImplDAO)SpringUtilTest.getBean("GoodsImplDAO");
	private static final GoodsSortDAO goodsSortDao = (GoodsSortDAO)SpringUtilTest.getBean("GoodsSortDAO");
	private static final LinkDAO linkDao = (LinkDAO)SpringUtilTest.getBean("LinkDAO");
	private static final MessageDAO messageDao = (MessageDAO)SpringUtilTest.getBean("MessageDAO");
	private static final NoteDAO noteDao = (NoteDAO)SpringUtilTest.getBean("NoteDAO");
	private static final PayDAO payDao = (PayDAO)SpringUtilTest.getBean("PayDAO");
	private static final PayGoodsDAO payGoodsDao = (PayGoodsDAO)SpringUtilTest.getBean("PayGoodsDAO");
	private static final ReplyDAO replyDao = (ReplyDAO)SpringUtilTest.getBean("ReplyDAO");
	private static final ShopDAO shopDao = (ShopDAO)SpringUtilTest.getBean("ShopDAO");
	private static final ShopGoodsSortDAO shopGoodsSortDao = (ShopGoodsSortDAO)SpringUtilTest.getBean("ShopGoodsSortDAO");
	private static final ShopStyleDAO shopStyleDao = (ShopStyleDAO)SpringUtilTest.getBean("ShopStyleDAO");
	private static final SupplierDAO supplierDao = (SupplierDAO)SpringUtilTest.getBean("SupplierDAO");
	private static final UserDAO userDao = (UserDAO)SpringUtilTest.getBean("UserDAO");
	private static final UserGradeDAO userGradeDao = (UserGradeDAO)SpringUtilTest.getBean("UserGradeDAO");
	private static final WebSiteDAO webSiteDao = (WebSiteDAO)SpringUtilTest.getBean("WebSiteDAO");
	//管理员保存
	public static Admin saveAdmin(){
		Admin admin = new Admin();
		admin.setAdminName("admin");
		admin.setAdminPassword("7FEF6171469E80D32C0559F88B377245");
		admin.setPowerId(0);
		return admin;
	}
	//广告保存
	public static Banner saveBanner(){
		Banner banner = new Banner();
		banner.setImgUrl("http://www.todaynic.com/admin/agentimg/a459400/ecfront.gif");
		banner.setInkUrl("www.ecfront.com");
		banner.setPlace(1);
		banner.setTagName("电子商务前沿");
		return banner;
	}
	public static List<GoodsBrand> saveBrand(){
		List<GoodsBrand> list = new ArrayList<GoodsBrand>();
		GoodsBrand brand = null;
		for(int i=0;i<20;i++){
			brand = new GoodsBrand();
			brand.setName("品牌"+i+"号");
			list.add(brand);
		}
		return list;
	}
	public static List<GoodsSort> saveGoodsSort1(){
		List<GoodsSort> list = new ArrayList<GoodsSort>();		
		GoodsSort gs = null;
		for(int i=0;i<5;i++){
			gs = new GoodsSort();
			gs.setName("分类"+i);
			gs.setGoodId(0);
			list.add(gs);
		}
		return list;
	}
	public static List<GoodsSort> saveGoodsSort2(){
		List<GoodsSort> list = new ArrayList<GoodsSort>();
		Set<GoodsBrand> gb = new HashSet<GoodsBrand>();
		gb.add(goodsBrandDao.findById(1));
		gb.add(goodsBrandDao.findById(2));
		gb.add(goodsBrandDao.findById(3));
		
		GoodsSort gs = null;
		for(int i=1;i<6;i++){
			GoodsSort gss = goodsSortDao.findById(i);
			gs = new GoodsSort();
			gs.setName("小类"+(i-1));
			gs.setGoodId(0);
			gs.setGoodId(gss.getId());
			gs.setGoodsBrands(gb);
			list.add(gs);
		}
		return list;
	}
	public static void main(String[] args) {
		adminDao.save(saveAdmin());
		bannerDao.save(saveBanner());

		for(Iterator<GoodsBrand> iter = saveBrand().iterator();iter.hasNext();){
			goodsBrandDao.save(iter.next());
		}

		for(Iterator<GoodsSort> iter = saveGoodsSort1().iterator();iter.hasNext();){
			goodsSortDao.save(iter.next());
		}
		
		for(Iterator<GoodsSort> iter = saveGoodsSort2().iterator();iter.hasNext();){
			goodsSortDao.save(iter.next());
		}
	}	
}